script_enemy_main{

let survivalcirclesize=1;
let survivalcirclespin=1;

let shot1=0;
let bullet1=[];
let timer1=[];
let speed1=[];
let size1=[];

let frame2=0;
let knives=0;
let maxsize=0;
let minsize=0;
let angle=rand_int(0,3)*90;
let shoot=0;
let speed=0;
let size=0;
let nr=0;
let xpos=0;
let ypos=GetClipMaxY;

let character="Sayuri";
let cutin=character;
let dispelled=0;
let spellcards=3;
let spellcardnumber=55;
let damagerate=10;
let outfit=5;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SElaserm3=("script\SoundEffects\laserm3.wav");
let SEshotm6=("script\SoundEffects\shotm6.wav");

let BG1=("\script\Images\BackgroundLayers\Sayuri2a.png");
let BG2=("\script\Images\BackgroundLayers\Sayuri2b.png");
let BG3=("\script\Images\OtherEffects\SpellCircle1a.png");
let GRboss=("\script\Images\CharacterSprites\Sayuri.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsSayuri1.txt");

	LoadSE("script\SoundEffects\laserm3.wav");
	LoadSE("script\SoundEffects\shotm6.wav");
	
	LoadGraphic("\script\Images\BackgroundLayers\Sayuri2a.png");
	LoadGraphic("\script\Images\BackgroundLayers\Sayuri2b.png");
	LoadGraphic("\script\Images\CharacterSprites\Sayuri.png");
	LoadGraphic("\script\Images\OtherEffects\SpellCircle1a.png");
	
	SetScore(750000);
	SetLife(500);
	SetTimer(65);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	
	SetX(GetCommonData("Boss1X"));
	SetY(GetCommonData("Boss1Y"));
	SetMovePosition02(cx,cx,50);
	
	SetDurableSpellCard;

	SetCommonData("Boss1Vanish",1);
}
	
@MainLoop{

//SetCollisionA(GetX,GetY,16);
//SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(32,32,32,32);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=2.5; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("[Devil's Torture Chamber]",spellcardnumber); 
HealthBar();
Portrait(cutin,2);


if(frame==120 || frame==240 || frame==360 || frame==480){ size=1; speed=2.5; minsize=20; maxsize=35; shoot=1; frame2=0; }
if(frame==660){ size=4; speed=2; minsize=30; maxsize=50; shoot=1; }
if(frame==960 && GetTimer>5){ knives++; angle=rand_int(0,3)*90; frame=0;  }
if(frame==90 || frame==210 || frame==330 || frame==450){ usespell=31; }

if(shoot==1){
if(angle==0){ xpos=minx; ypos=maxy; }
if(angle==90){ xpos=minx; ypos=miny; }
if(angle==180){ xpos=maxx; ypos=miny; }
if(angle==270){ xpos=maxx; ypos=maxy; }
	loop(size){
		loop(20){
		if(angle==0){ xpos=minx; if(ypos>miny){ ypos-=rand(minsize,maxsize); } }
		if(angle==90){ if(xpos<maxx){ xpos+=rand(minsize,maxsize); } ypos=miny; }
		if(angle==180){ xpos=maxx; if(ypos<maxy){ ypos+=rand(minsize,maxsize); } }
		if(angle==270){ if(xpos>minx){ xpos-=rand(minsize,maxsize); } ypos=maxy; }

		if(xpos>=minx && xpos<=maxx && ypos>=miny && ypos<=maxy){
		shot1=(Obj_Create(OBJ_LASER));
		Obj_SetPosition(shot1,xpos,ypos);
		Obj_SetAngle(shot1,angle+rand(-6,6));
		Obj_SetSpeed(shot1,0);
		Obj_SetAutoDelete(shot1,false);
		ObjShot_SetDelay(shot1,0);
		ObjShot_SetGraphic(shot1,59);
		ObjLaser_SetLength(shot1,15);
		ObjLaser_SetWidth(shot1,12);
		ObjLaser_SetSource(shot1,false);
		bullet1=bullet1~[shot1];
		timer1=timer1~[shot1];
		timer1[length(bullet1)-1]=0;
		speed1=speed1~[shot1];
		speed1[length(bullet1)-1]=speed;
		size1=size1~[shot1];
		size1[length(bullet1)-1]=15;
		}
		}
	angle+=90;
	if(angle>=360){ angle-=360; }
	}
size=1;
shoot=0;
PlaySE(SElaserm3);
}

if((frame2==0 || frame==0) && frame<480){ SetMovePosition02(cx+170*cos(angle+180),cy+190*sin(angle+180),60); }
if(frame==570){ SetMovePosition02(cx,cy,60); }
if(frame==660){ usespell=-60; }

let size2=18;
let bulletspeed=2;

if(frame>=120){

if(time%30==0 && frame2>=0 && frame2<30+(knives*30) && angle==0){
let xpos2=maxx;
let ypos2=miny+rand(-((maxy-miny)/size2),((maxy-miny)/size2));
	loop(size2+1){
	CreateShot02(xpos2,ypos2,bulletspeed*2,angle+180,-0.2,bulletspeed,61,20);
	ypos2+=(maxy-miny)/size2;
	}
PlaySE(SEshotm6);
}
if(time%30==0 && frame2>=0 && frame2<30+(knives*30) && angle==90){
let xpos2=minx+rand(-((maxx-minx)/size2),((maxx-minx)/size2));
let ypos2=maxy;
	loop(size2+1){
	CreateShot02(xpos2,ypos2,bulletspeed*2,angle+180,-0.2,bulletspeed,61,20);
	xpos2+=(maxx-minx)/size2;
	}
PlaySE(SEshotm6);
}
if(time%30==0 && frame2>=0 && frame2<30+(knives*30) && angle==180){
let xpos2=minx;
let ypos2=miny+rand(-((maxy-miny)/size2),((maxy-miny)/size2));
	loop(size2+1){
	CreateShot02(xpos2,ypos2,bulletspeed*2,angle+180,-0.2,bulletspeed,61,20);
	ypos2+=(maxy-miny)/size2;
	}
PlaySE(SEshotm6);
}
if(time%30==0 && frame2>=0 && frame2<30+(knives*30) && angle==270){
let xpos2=minx+rand(-((maxx-minx)/size2),((maxx-minx)/size2));
let ypos2=miny;
	loop(size2+1){
	CreateShot02(xpos2,ypos2,bulletspeed*2,angle+180,-0.2,bulletspeed,61,20);
	xpos2+=(maxx-minx)/size2;
	}
PlaySE(SEshotm6);
}

if(time%30==0 && frame>=660 && frame<690+(knives*30)){
let angle2=-45+rand(-(90/10),(90/10));
	loop(12){
	CreateShot02(minx,miny,bulletspeed*2,45-angle2,-0.2,bulletspeed/2,61,20);
	CreateShot02(maxx,miny,bulletspeed*2,135-angle2,-0.2,bulletspeed/2,61,20);
	CreateShot02(maxx,maxy,bulletspeed*2,225-angle2,-0.2,bulletspeed/2,61,20);
	CreateShot02(minx,maxy,bulletspeed*2,315-angle2,-0.2,bulletspeed/2,61,20);
	angle2+=90/12;
	}
PlaySE(SEshotm6);
}

} //time>=120


let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); speed1=erase(speed1,i); size1=erase(size1,i);
	i--;
	}
	else{
	Obj_SetPosition(bullet1[i],Obj_GetX(bullet1[i])+0*cos(Obj_GetAngle(bullet1[i])),Obj_GetY(bullet1[i])+0*sin(Obj_GetAngle(bullet1[i])));
	ObjLaser_SetLength(bullet1[i],size1[i]);

	size1[i]=size1[i]+speed1[i];
	if(size1[i]>=500){ ObjShot_FadeDelete(bullet1[i]); }

	timer1[i]=timer1[i]+1;
	}
i++;
}

frame2++;

time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
	if(bgfade<255){ bgfade+=5; }
	SetGraphicRect(0,0,300,300);
	SetGraphicScale(1.5,1.5);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
	
	SetGraphicRect(0,0,100,100);
	SetGraphicScale(2.5,2.5);
	SetAlpha(bgfade);
	SetRenderState(ADD);
	SetGraphicAngle(0,0,0);
	SetTexture(BG2);
	
	SetColor(255,0,0);
	DrawGraphic(cx+140*cos(time)*1.7,cy+140*sin(time*1.4));
	SetColor(0,255,0);
	DrawGraphic(cx-120*cos((time+120)*1.2),cy-170*sin((time+120)*1.8));
	SetColor(0,0,255);
	DrawGraphic(cx-90*cos((time+240)*2),cy+110*sin((time+240)*1.3));

if(survivalcirclesize>0){
	SetGraphicRect(0,0,200,200);
	SetGraphicScale(survivalcirclesize*1.4,survivalcirclesize*1.4);
	SetRenderState(ALPHA);
	SetTexture(BG3);
	SetAlpha(bgfade/2);
	SetColor(70+60*cos((time+0)/2),70+60*cos((time+120)/2),70+60*cos((time+240)/2));
	SetGraphicAngle(0,0,survivalcirclespin*1.2);
	DrawGraphic(cx,cy);
	
	SetGraphicRect(0,0,200,200);
	SetGraphicScale(survivalcirclesize*2,survivalcirclesize*2);
	SetTexture(BG3);
	SetAlpha(bgfade/2);
	SetColor(170+60*cos((time+0)/2),170+60*cos((time+120)/2),170+60*cos((time+240)/2));
	SetGraphicAngle(0,0,-survivalcirclespin*0.7);
	DrawGraphic(cx,cy);
}
survivalcirclespin++;
if(GetLife<=0 && survivalcirclesize>0){ survivalcirclesize-=0.03; }

}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
//	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,5);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
	
	if(GotSpellCardBonus && GetCommonData("TrumpCardUnlocked")[10]==0){
		let spellcarddataarray=GetCommonData("NewTrumpCardsUnlocked");
		spellcarddataarray[10]=1;
		SetCommonData("NewTrumpCardsUnlocked",spellcarddataarray);	

		let spellcarddataarray=GetCommonData("TrumpCardUnlocked");
		spellcarddataarray[10]=1;
		SetCommonData("TrumpCardUnlocked",spellcarddataarray);
		
		let spellcarddataarray=GetCommonData("SpellcardData");
		spellcarddataarray[77]=0.5;
		SetCommonData("SpellcardData",spellcarddataarray);
		
		SetCommonData("NewTrumpCardUnlocked",true);
		SaveCommonData;
	}
}

}